
import path from "path";
// const HtmlWebpackPlugin = require("html-webpack-plugin");

// vue-loader 配套插件
const {VueLoaderPlugin} = require("vue-loader");
module.exports = {
    mode: "production",
    entry: path.resolve(__dirname, '../packages/d-ui/index.ts'),

    output: {
        path: path.resolve(__dirname, '../lib'),
        filename: 'index.js',
        libraryTarget: "umd",
        library: 'd-ui', 
    },
    externals: {
        // 排除全局Vue import xx from "vue" 这种的
        vue: {
            root: "Vue",   //通过 script 标签引入，此时全局变量中可以访问的是 Vue
            commonjs: "vue",  //可以将vue作为一个 CommonJS 模块访问
            commonjs2: "vue",  //和上面的类似，但导出的是 module.exports.default
            amd: "vue"   //类似于 commonjs，但使用 AMD 模块系统
          }
    },
    resolve: {
        // 解析模块
        extensions: ['.ts', '.tsx', '.js', '.vue'] 
    },
    module: {
        rules: [
            {
                test: /\.(ts|js)x?$/,
                exclude: /node_modules/,
                loader: "babel-loader", // 用这个需要.babelrc
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader',
            },
            {
                test: /\.(svg|otf|ttf|woff)$/,
                loader: 'url-loader',
            },
            {
                test: /\.(scss|css)$/,
                use: [
                    'style-loader',
                    'css-loader',
                    'sass-loader',
                ]
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        // new HtmlWebpackPlugin({
        //     template: path.resolve(__dirname, 'template.html'),
        // }),
    ]
}